<?php
/**
 * Deligator for InPatient module
 *
 */
$loader->requireOnce('includes/RadConnector/IRadConnector.class.php');
$loader->requireOnce('includes/RadConnector/RadQueueConnector.class.php');
class InPatientRadConnector implements  IRadConnector {
	private $logger;
    function __construct(){
        $this->logger = LoggerManager::getLogger('includes.RadConnector.InPatientRadConnector');
    }
    public function doAfterCreateAssignment($data) {
    	$this->logger->info("Start function doAfterCreateAssignment {ticketId=" . $data['ticketId'] . ", radTicketId=}" . $data['radTicketId']);
    	// Create in_ticket_item record
    	$itemType  =   Utils::getEnumKey(EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE, EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE_RADIOLOGY);
        $objInTicketItem    =   ORDataObject::factory('InTicketItem');
        $objInTicketItem->populateArray(
            array(
                'date'              =>  date('Y-m-d H:i:s'),
                'ticketId'          =>  $data['ticketId'],
                'enum_item_type'    =>  $itemType,
                'item_id'           =>  $data['radTicketId']
            )
        );
        $objInTicketItem->persist();

        // Add rad_ticket to radiology waiting queue
        $objQueueConnector  =   new RadQueueConnector();
        $objQueueConnector->addAssignmentTicketToWaitingQueue($data);
        $this->logger->info("Finish function doAfterCreateAssignment {ticketId=" . $data['ticketId'] . ", radTicketId=}" . $data['radTicketId']);
    }

    public function doBeforeCreateAssignment($data){

    }

    public function doAfterFinishAssignment($itemId, $itemType, $data){
        $this->logger->info("Start function doAfterFinishAssignment {itemId=$itemId, itemType=$itemType}");
        $itemType  =   Utils::getEnumKey(EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE, EnumerationConstant::IN_TICKE_ITEM_ITEMTYPE_RADIOLOGY);
        ORDataObject::factory('InTicketItem')->updateData($itemId, $itemType, $data, false);
        $this->logger->info("Finish function doAfterFinishAssignment {itemId=$itemId, itemType=$itemType}");
    }

    public function doAfterDeleteAssignment($itemId, $enumItemType) {
    	$this->logger->info("Start function doAfterDeleteAssignment {itemId=$itemId, enumItemType=$enumItemType}");
        $objInTicketItem    =   ORDataObject::factory('InTicketItem');
        $objInTicketItem->deleteItem($itemId, $enumItemType);
        $this->logger->info("Finish function doAfterDeleteAssignment {itemId=$itemId, enumItemType=$enumItemType}");
    }

    public function doAfterCancelAssignment($radTicketId, $enumRadType) {

    }

    public function doAfterStartAssignment($radTicketId, $enumRadType) {

    }
}
?>